package com.mor.shiro.uitls;

import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zht
 * @version 1.0
 * @createDate 2020/11/17 22:44
 */

public class StringUtil {
    public static void main(String[] args) {
        String string= "[w][企业名称][w][我天啊]";
        String [] strings = getMedian(string);
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
        System.out.println(judgeString(strings));
    }

    public static String [] getMedian(String string){
        char [] chars = string.toCharArray();
        boolean begin = false;
        StringBuffer temp =new StringBuffer();
        List<String> list =new ArrayList<>();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i]=='['){
                begin=true;
            }else if(chars[i]==']'){
                if (StringUtils.isNotEmpty(temp.toString())){
                    list.add(temp.toString());
                }
                temp =new StringBuffer();
                begin=false;
            }else{
                if(begin){
                    temp.append(chars[i]);
                }
            }
        }
        return list.toArray(new String[0]);
    }

    public static boolean judgeString (String [] strings){
        for (int i = 1; i < strings.length; i++) {
            if ("w".equals(strings[i - 1])&&strings[i-1].equals(strings[i])){
                return false;
            }
        }
        return true;
    }
}
